package cn.zf233.springsecurityjwt.config.upwd;

import cn.zf233.springsecurityjwt.entity.User;
import cn.zf233.springsecurityjwt.service.UserService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.security.core.userdetails.UserDetailsService;
import org.springframework.security.core.userdetails.UsernameNotFoundException;
import org.springframework.stereotype.Service;

/**
 * Created by zf233 on 2021/7/12
 */
@Slf4j
@Service("uPwdDetailsService")
public class UPwdDetailsService implements UserDetailsService {

    @Autowired
    private UserService userService;

    @Override
    public UserDetails loadUserByUsername(String username) throws UsernameNotFoundException {
        log.info("准备加载用户信息:" + username);
        User userByUsername = userService.getUserByUsername(username);
        if (userByUsername != null) {
            log.info("用户{}验证通过", username);
            return userByUsername;
        }
        return null;
    }
}
